package gui;
import java.io.IOException;
import javax.swing.JOptionPane;
import com.google.gdata.util.ServiceException;

import database.Database;
import stopwatch.StopwatchPanel;
import utility.Constants;
import utility.DisplayUpdateException;
import utility.GooglePoster;

public final class Stopwatch extends StcalWindow{

	private static final long serialVersionUID = 1L;
	private final static int STARTUP_TIME = 5000;

	private Stopwatch(){};

	private static void launch(){
		Database.addMaintenanceCost(STARTUP_TIME);
		new StopwatchPanel();
		if (Constants.activities.length < 1) throw new RuntimeException("Maintenance activity not found.\n");
	}

	public static void main(final String[] args) throws IOException, ServiceException{
		try{
			GooglePoster.post2Google();			
		}

		catch (DisplayUpdateException d){
			displayResults(d.getMessage());
			launch();
		}

		catch(ServiceException s){
			displayResults(s.getMessage());
			launch();
		}

		catch(Exception e){
			JOptionPane.showMessageDialog(new JOptionPane(), RAISED_EXEP);
			e.printStackTrace();
			System.exit(-1);
		}
	}
}
